package com.yict.csms.system.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.yict.common.dao.impl.CommonDao;
import com.yict.csms.system.entity.User;

/**
 * 
 * 
 * @author Patrick.Deng
 * 
 */
@Repository
public class UserDaoImpl extends CommonDao<User, Long> {

	public User getUserByName(String userName, String passWord)
			throws Exception {
		User user = null;
		String queryString = " from User as u where u.userName = :userName and u.userPassWord = :userPassWord";
		try {
			Query query = this.getSession().createQuery(queryString);
			query.setParameter("userName", userName);
			query.setParameter("userPassWord", passWord);
			List<User> list = query.list();
			if (list != null && list.size() > 0) {
				user = list.get(0);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return user;
	}

	public void changeStatus(List<Long> userIds, String status) {
		String queryString = "update User t set t.userStutas = :status where t.userId in (:userIds)";
		Query query = this.getSession().createQuery(queryString);
		query.setParameter("status", status);
		query.setParameterList("userIds", userIds);
		query.executeUpdate();
	}
}
